﻿using System;

namespace Simp.CodeModel.CoreFunctions
{
	/// <summary>Encapsultes the functionality of forcing approximation on a function to simplify it.</summary>
	public class EvalFunction : IFunction
	{
		private static readonly string[] PARAMETER_NAMES = new[] { "f" };

		#region IFunction Members
		string IFunction.FunctionName
		{
			get { return "Eval"; }
		}

		string[] IFunction.ParameterNames
		{
			get { return PARAMETER_NAMES; }
		}

		IFunctionParameterBinding[] IFunction.DefaultParameterValues
		{
			get { return FunctionHelper.EmptyBindings; }
		}

		IFunction IFunction.Simplify(SimplificationMode simplificationMode, params IFunction[] parameters)
		{
			FunctionHelper.ValidateParameters(this, parameters);

			IFunction function = parameters[0];

			if (simplificationMode != SimplificationMode.AllowApproximation)
			{
				IFunction newFunction = function.Simplify(SimplificationMode.AllowApproximation);

				if (newFunction != null)
				{
					return newFunction;
				}
				else
				{
					return function;
				}
			}
			else
			{
				return function;
			}
		}

		IFunction IFunction.AcceptVisitor(IFunctionVisitor visitor)
		{
			return null;
		}
		#endregion
	}
}